package com.shop.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.shop.entity.Result;
import com.shop.mapper.ProductMapper;
import com.shop.pojo.Product;
import com.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    /** 1.添加商品 */
    @Override
    public Result addProduct(Product product) {
        Result result = null;
        if(product == null || StringUtils.isEmpty(product.getName())||
                StringUtils.isEmpty(product.getImage())||
                product.getNumber()==null|| product.getNumber()<=0||
                StringUtils.isEmpty(product.getBesc())||
                product.getPrice()==null||product.getPrice()<=0||
                product.getCategory()==null){
            result = new Result(false,"请填写完整信息");
        }else {
            product.setId(UUID.randomUUID().toString());
            product.setIsHot(0);
            product.setStatus(1);
            product.setImage("http://120.79.240.142:8080/images/"+product.getImage());
            product.setCreateTime(new Date());
            product.setUpdateTime(new Date());
            productMapper.insertSelective(product);
            result = new Result(true,"添加成功",product);
        }
        return result;
    }

    @Override
    /** 2.查询指定商品（根据书的id） */
    public Product findProductById(String id) {
        Product product = productMapper.selectByPrimaryKey(id);
        return product;
    }

    @Override
    /** 3.查询所有商品  (正在出售的) */
    public List<Product> findAllProducts() {
        return null;
    }

    @Override
    /** 4.删除商品 */
    public List<Product> findLatestProducts(String pid) {
        return null;
    }

    @Override
    /** 5.修改商品 */
    public Result updateProduct(Product product) {
        return null;
    }

}
